home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / gen / PHPQ.hP < prev    next >
Text File  |  1992-04-14  |  2KB  |  109 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.     adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef <T>PHPQ_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define <T>PHPQ_h 1
  25.  
  26. #include "<T>.PQ.h"
  27.  
  28. #ifndef <T>PHPQIndex
  29. #define <T>PHPQIndex unsigned short
  30. #endif
  31.  
  32. struct <T>PHPQNode
  33. {
  34.   <T>PHPQIndex   sibling;
  35.   <T>PHPQIndex   children;
  36.   <T>            item;
  37.   char           valid;
  38. };
  39.  
  40.  
  41. class <T>PHPQ : public <T>PQ
  42. {
  43.   <T>PHPQNode*  storage;        // table -- freelist in storage[0].sibling
  44.   int           root;
  45.   int           size;
  46.  
  47.   void          prealloc(int);
  48.   int           check_sibling_list(int);
  49.  
  50. public:
  51.  
  52.                 <T>PHPQ(int sz = DEFAULT_INITIAL_CAPACITY);
  53.                 <T>PHPQ(<T>PHPQ&);
  54.                 ~<T>PHPQ();
  55.  
  56.   Pix           enq(<T&> item);
  57.   <T>           deq(); 
  58.  
  59.   <T>&          front();
  60.   void          del_front();
  61.  
  62.   int           contains(<T&> item);
  63.  
  64.   void          clear(); 
  65.  
  66.   Pix           first(); 
  67.   void          next(Pix& i);
  68.   <T>&          operator () (Pix i);
  69.   void          del(Pix i);
  70.   Pix           seek(<T&> item);
  71.  
  72.   int           OK();                    // rep invariant
  73. };
  74.  
  75.  
  76. inline <T>PHPQ::~<T>PHPQ()
  77. {
  78.   delete [] storage;
  79. }
  80.  
  81.  
  82. inline <T> <T>PHPQ::deq()
  83. {
  84.   if (count == 0) error("deq of empty PQ");
  85.   <T> x = storage[root].item;
  86.   del_front();
  87.   return x;
  88. }
  89.  
  90.  
  91. inline <T>& <T>PHPQ::front()
  92. {
  93.   if (count == 0) error("front of empty PQ");
  94.   return storage[root].item;
  95. }
  96.  
  97. inline int <T>PHPQ::contains(<T&> item)
  98. {
  99.   return seek(item) != 0;
  100. }
  101.  
  102. inline <T>& <T>PHPQ::operator() (Pix p)
  103. {
  104.   if (p == 0) error("null Pix");
  105.   return storage[int(p)].item;
  106. }
  107.  
  108. #endif
  109.